<template>
  <div class="page_body">
    <HomeTop :topTitle="topTitle"></HomeTop>

    <div class="page_list">
      <div v-if="applyList.length">
        <div
          class="list_box"
          v-for="(item, index) in applyList"
          :key="index"
          @click="goApplyDetails(item.order_status, item.order_id)"
        >
          <div class="title">{{ item.title }}</div>
          <div class="msg">
            <img
              class="img"
              src="../../assets/image/team_img.png"
              alt=""
            /><span>{{ item.team_name }}</span>
          </div>
          <div class="msg">
            <img
              class="img"
              src="../../assets/image/address_icon01.png"
              alt=""
            /><span>{{ item.address }}</span>
          </div>
          <div class="msg">
            <img
              class="img"
              src="../../assets/image/time_icon01.png"
              alt=""
            /><span>{{ item.start_date }}</span>
          </div>
          <div class="price">￥{{ item.money }}</div>

          <div v-if="item.order_status == 2" class="order_type paid">
            已支付
          </div>
          <div v-if="item.order_status == 1" class="order_type unpaid">
            待支付
          </div>
          <!-- <div v-if="item.order_status==3" class="order_type failed">已失效</div> -->
          <div
            class="btn"
            v-if="item.order_status == 1"
            @click.stop="cancelApply(item.order_id)"
          >
            取消报名
          </div>
        </div>
      </div>
      <div class="listEmpty" v-else>
        <div class="emptyBox">
          <img
            class="empty_img"
            src="../../assets/image/empty_icon01.png"
            alt=""
          />
          <div class="empty_title">暂无订单</div>
        </div>
      </div>
    </div>
  </div>
</template>
<style src="../../assets/css/function/myApply.css" scoped></style>

<script>
import HomeTop from "@/components/homeTop.vue";
import { Indicator, Toast, MessageBox } from "mint-ui";
export default {
  name: "myApply",
  components: {
    HomeTop,
  },
  data() {
    return {
      topTitle: "我的报名",
      applyList: "",
    };
  },
  mounted() {
    this.getApplyList();
  },
  methods: {
    goApplyDetails(status, id) {
      // console.log(status, id);
      if (status == 1) {
        this.$router.push({
          name: "applyDetails",
          query: {
            orderId: id,
          },
        });
      }
      if (status == 2) {
        this.$router.push({
          name: "applySuccessDetails",
          query: {
            orderId: id,
          },
        });
      }
    },
    //取消报名
    cancelApply(id) {
      MessageBox({
        message: "确认取消报名?",
        confirmButtonText: "确认",
        showCancelButton: true,
      }).then((action) => {
        if (action == "confirm") {
          let url = "/mobile/cancelEnroll";
          let data = {
            order_id: id,
          };
          this.axios
            .post(url, data)
            .then((response) => {
              if (response.code == 0) {
                this.getApplyList();
              } else {
                Toast({
                  message: res.msg,
                  duration: 3000,
                });
              }
            })
            .catch(function (error) {
              console.log(error);
            });
        }
      });
    },
    //获取报名列表
    getApplyList() {
      let url = "/mobile/enrollList";
      Indicator.open();
      this.axios
        .post(url)
        .then((res) => {
          Indicator.close();
          if (res.code == 0) {
            this.applyList = res.enroll;
          } else {
            Toast({
              message: res.msg,
              duration: 3000,
            });
          }
        })
        .catch(function (error) {
          Indicator.close();
          console.log(error);
        });
    },
  },
};
</script>
